/**
 * 部门详情对话框
 */
var DeptInfoDlg = {
    data: {
        deptId: "",
        deptName: ""
    }
};

layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func', 'laydate', 'upload'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var laydate = layui.laydate;
    var upload = layui.upload;

    laydate.render({
        elem: '#timeLimit',
        tiger: 'click'
    });



    // 点击部门时
    $('#deptName').click(function () {
        var formName = encodeURIComponent("parent.DeptInfoDlg.data.deptName");
        var formId = encodeURIComponent("parent.DeptInfoDlg.data.deptId");
        var treeUrl = encodeURIComponent("/dept/tree");

        layer.open({
            type: 2,
            title: '部门',
            area: ['300px', '400px'],
            content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
            end: function () {
                $("#deptId").val(DeptInfoDlg.data.deptId);
                $("#deptName").val(DeptInfoDlg.data.deptName);
            }
        });
    });

    /**
     * 检索店名
     */
    var languageAjax = new $ax(Feng.ctxPath + "/btyWage/getDm");
    var languageResult = languageAjax.start();
    $.each(languageResult, function (index, val) {
        $("#shopName").append("<option value='" + val.dm + "'>" + val.dm + "</option>");
    });
    form.render('select');

    /**
     * 检索职务
     */
    var languageAjax = new $ax(Feng.ctxPath + "/btyWx/getPost");
    var languageResult = languageAjax.start();
    $.each(languageResult, function (index, val) {
        $("#post").append("<option value='" + val.zw + "'>" + val.zw + "</option>");
    });
    form.render('select');

    /**
     * 检索区域
     */
    var qyAjax = new $ax(Feng.ctxPath + "/btyWx/getRegionOne");
    var qyResult = qyAjax.start();
    $.each(qyResult, function (index, val) {
        $("#regionOne").append("<option value='" + val.qy + "'>" + val.qy + "</option>");
    });
    form.render('select');

    form.on('select(regionOne)', function (data) {
        var regionOne = data.value;
        if (regionOne == "") {
            $("#regionTwo").html("");
            $("#regionTwo").append("<option value=''>全部</option>")
            form.render('select');
        } else {
            var qyAjax = new $ax(Feng.ctxPath + "/btyWx/getRegionTwo");
            qyAjax.set("region", regionOne);
            var qyResult = qyAjax.start();
            $("#regionTwo").html("");
            $.each(qyResult, function (index, val) {
                $("#regionTwo").append("<option value='" + val.eqy + "'>" + val.eqy + "</option>");
            });
            form.render('select');
        }
    });


    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/btyWx/add", function (data) {
        }, function (data) {
            Feng.success("添加成功!");
            admin.putTempData('formOk', true);
            admin.closeThisDialog();
        });
        ajax.set(data.field);
        ajax.start();

        //添加 return false 可成功跳转页面
        return false;
    });
});